/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mysql.process;

import entity.function.Requset;

/**
 *
 * @author dell
 */
public class LevelQueueArray 
{
//columns_______________________________________________________________________    
private LevelQueue[] queue;
private String target;
private int count;
//functions_____________________________________________________________________
     //operators________________________________________________________________
public LevelQueueArray()
{
     
}
public LevelQueueArray(LevelQueue[] queue,String target)
{
     this.queue=queue;
     this.target=target;
}
public LevelQueueArray(int[] levels,int maxsizes,String target)
{
     this.queue=new LevelQueue[levels.length];
     for(int i=0;i<levels.length;i++)
     {
         this.queue[i]=new LevelQueue(maxsizes,"entity.function.Requset",levels[i]);
     }
     this.target=target;
}
     //getter__________________________________________________________________
public String getTarget() 
{
     return target;
}
     //setter___________________________________________________________________
public void setTarget(String target) 
{
     this.target = target;
}
     //operator_________________________________________________________________
public synchronized boolean insert(Requset value)
{
     boolean result=false;
     for(int i=0;i<this.queue.length;i++)
     {
         if(this.queue[i].isAvailable()) 
         {
             this.queue[i].insert(value);
             result=true;
         }
         else if(value.getLevel()<=this.queue[i].getLevel()&&!this.queue[i].isFull())
         {
             this.queue[i].insert(value);
             result=true;
         }   
     }
     return result;
}
private Requset pop(int index)
{
     Object o=this.queue[index].pop();
     return (Requset)o;
}
public void hand()
{
     this.pop(this.count%this.queue.length);
     for(int i=0;i<this.queue.length;i++)
     {
          this.pop(this.count%this.queue[i].getLevel());
     }
     this.count++;
}

}
